package com.zwface.demo.function.attendance.adapter;

import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.StringUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.qmuiteam.qmui.widget.QMUIRadiusImageView;
import com.zwface.demo.R;
import com.zwface.demo.model.db.Attendance;


/**
 * created by 张中文
 * on 2020/4/28
 * 描述：
 */
public class AttendanceLsAdapter extends BaseQuickAdapter<Attendance, BaseViewHolder>
{
    public AttendanceLsAdapter() {
        super(R.layout.item_attendance_ls,null);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, Attendance item) {
        QMUIRadiusImageView imageView = helper.getView(R.id.img_photo);
        TextView tv_course = helper.getView(R.id.tv_course);
        Button btnAttendance = helper.getView(R.id.btn_attendace);

        helper.setText(R.id.tv_name,item.getStuName());
        Glide.with(imageView)
                .load(item.getFace())
                .placeholder(R.mipmap.ic_launcher)
                .into(imageView);

        if(item.getId() == null){
            //未签到
            helper.setText(R.id.tv_time,"未签到");
            btnAttendance.setVisibility(View.VISIBLE);
            helper.addOnClickListener(R.id.btn_attendace);
            tv_course.setVisibility(View.GONE);
        }else {
            //已签到
            helper.setText(R.id.tv_time,item.getSignTime());
            btnAttendance.setVisibility(View.GONE);

            if(!StringUtils.isEmpty(item.getCourseName())){
                tv_course.setText("课程："+item.getCourseName());
                tv_course.setVisibility(View.VISIBLE);
            }else {
                tv_course.setVisibility(View.GONE);
            }
        }
    }
}
